###############################################
# === xenomorph_espionage_events.txt ===
###############################################
###############################################
# XENOMORPH ESPIONAGE EVENTS
# Pass 24: Stage completion events for the 6 Xenomorph operations.
###############################################

namespace = xenomorph_op

country_event = {
	id = xenomorph_op.1
	title = xenomorph_op.1.name
	desc = xenomorph_op.1.desc
	picture = GFX_evt_alien_artifacts
	is_triggered_only = yes

	option = { name = xenomorph_op.1.a }
}

country_event = {
	id = xenomorph_op.2
	title = xenomorph_op.2.name
	desc = xenomorph_op.2.desc
	picture = GFX_evt_alien_artifacts
	is_triggered_only = yes

	immediate = {
		add_resource = { society_research = 200 }
		from = { set_timed_country_flag = { flag = xeno_biological_survey_completed days = 10800 } }
	}

	option = { name = xenomorph_op.2.a }
}

country_event = {
	id = xenomorph_op.10
	title = xenomorph_op.10.name
	desc = xenomorph_op.10.desc
	picture = GFX_evt_alien_artifacts
	is_triggered_only = yes

	option = { name = xenomorph_op.10.a }
}

country_event = {
	id = xenomorph_op.11
	title = xenomorph_op.11.name
	desc = xenomorph_op.11.desc
	picture = GFX_evt_alien_artifacts
	is_triggered_only = yes

	option = { name = xenomorph_op.11.a }
}

country_event = {
	id = xenomorph_op.12
	title = xenomorph_op.12.name
	desc = xenomorph_op.12.desc
	picture = GFX_evt_alien_artifacts
	is_triggered_only = yes

	immediate = {
		from = { add_modifier = { modifier = xeno_country_infested days = 10800 } }
	}

	option = { name = xenomorph_op.12.a }
}

country_event = {
	id = xenomorph_op.20
	title = xenomorph_op.20.name
	desc = xenomorph_op.20.desc
	picture = GFX_evt_alien_artifacts
	is_triggered_only = yes

	option = { name = xenomorph_op.20.a }
}

country_event = {
	id = xenomorph_op.21
	title = xenomorph_op.21.name
	desc = xenomorph_op.21.desc
	picture = GFX_evt_alien_artifacts
	is_triggered_only = yes

	option = { name = xenomorph_op.21.a }
}

country_event = {
	id = xenomorph_op.22
	title = xenomorph_op.22.name
	desc = xenomorph_op.22.desc
	picture = GFX_evt_alien_artifacts
	is_triggered_only = yes

	option = { name = xenomorph_op.22.a }
}

country_event = {
	id = xenomorph_op.23
	title = xenomorph_op.23.name
	desc = xenomorph_op.23.desc
	picture = GFX_evt_alien_artifacts
	is_triggered_only = yes

	immediate = {
		from = { add_modifier = { modifier = xeno_country_compromised_lineage days = 3650 } }
	}

	option = { name = xenomorph_op.23.a }
}

country_event = {
	id = xenomorph_op.30
	title = xenomorph_op.30.name
	desc = xenomorph_op.30.desc
	picture = GFX_evt_alien_artifacts
	is_triggered_only = yes

	option = { name = xenomorph_op.30.a }
}

country_event = {
	id = xenomorph_op.31
	title = xenomorph_op.31.name
	desc = xenomorph_op.31.desc
	picture = GFX_evt_alien_artifacts
	is_triggered_only = yes

	option = { name = xenomorph_op.31.a }
}

country_event = {
	id = xenomorph_op.32
	title = xenomorph_op.32.name
	desc = xenomorph_op.32.desc
	picture = GFX_evt_alien_artifacts
	is_triggered_only = yes

	option = { name = xenomorph_op.32.a }
}

country_event = {
	id = xenomorph_op.33
	title = xenomorph_op.33.name
	desc = xenomorph_op.33.desc
	picture = GFX_evt_alien_artifacts
	is_triggered_only = yes

	option = { name = xenomorph_op.33.a }
}

country_event = {
	id = xenomorph_op.34
	title = xenomorph_op.34.name
	desc = xenomorph_op.34.desc
	picture = GFX_evt_alien_artifacts
	is_triggered_only = yes

	immediate = {
		from = { add_modifier = { modifier = xeno_country_leadership_compromised days = 7200 } }
	}

	option = { name = xenomorph_op.34.a }
}

country_event = {
	id = xenomorph_op.40
	title = xenomorph_op.40.name
	desc = xenomorph_op.40.desc
	picture = GFX_evt_alien_artifacts
	is_triggered_only = yes

	option = { name = xenomorph_op.40.a }
}

country_event = {
	id = xenomorph_op.41
	title = xenomorph_op.41.name
	desc = xenomorph_op.41.desc
	picture = GFX_evt_alien_artifacts
	is_triggered_only = yes

	option = { name = xenomorph_op.41.a }
}

country_event = {
	id = xenomorph_op.42
	title = xenomorph_op.42.name
	desc = xenomorph_op.42.desc
	picture = GFX_evt_alien_artifacts
	is_triggered_only = yes

	option = { name = xenomorph_op.42.a }
}

country_event = {
	id = xenomorph_op.43
	title = xenomorph_op.43.name
	desc = xenomorph_op.43.desc
	picture = GFX_evt_alien_artifacts
	is_triggered_only = yes

	option = { name = xenomorph_op.43.a }
}

country_event = {
	id = xenomorph_op.44
	title = xenomorph_op.44.name
	desc = xenomorph_op.44.desc
	picture = GFX_evt_alien_artifacts
	is_triggered_only = yes

	immediate = {
		from = { add_modifier = { modifier = xeno_country_brood_uprising days = 1825 } }
	}

	option = { name = xenomorph_op.44.a }
}

country_event = {
	id = xenomorph_op.50
	title = xenomorph_op.50.name
	desc = xenomorph_op.50.desc
	picture = GFX_evt_alien_artifacts
	is_triggered_only = yes

	option = { name = xenomorph_op.50.a }
}

country_event = {
	id = xenomorph_op.51
	title = xenomorph_op.51.name
	desc = xenomorph_op.51.desc
	picture = GFX_evt_alien_artifacts
	is_triggered_only = yes

	option = { name = xenomorph_op.51.a }
}

country_event = {
	id = xenomorph_op.52
	title = xenomorph_op.52.name
	desc = xenomorph_op.52.desc
	picture = GFX_evt_alien_artifacts
	is_triggered_only = yes

	option = { name = xenomorph_op.52.a }
}

country_event = {
	id = xenomorph_op.53
	title = xenomorph_op.53.name
	desc = xenomorph_op.53.desc
	picture = GFX_evt_alien_artifacts
	is_triggered_only = yes

	option = { name = xenomorph_op.53.a }
}

country_event = {
	id = xenomorph_op.54
	title = xenomorph_op.54.name
	desc = xenomorph_op.54.desc
	picture = GFX_evt_alien_artifacts
	is_triggered_only = yes

	option = { name = xenomorph_op.54.a }
}

country_event = {
	id = xenomorph_op.55
	title = xenomorph_op.55.name
	desc = xenomorph_op.55.desc
	picture = GFX_evt_alien_artifacts
	is_triggered_only = yes

	option = { name = xenomorph_op.55.a }
}

country_event = {
	id = xenomorph_op.56
	title = xenomorph_op.56.name
	desc = xenomorph_op.56.desc
	picture = GFX_evt_alien_artifacts
	is_triggered_only = yes

	immediate = {
		from = { add_modifier = { modifier = xeno_country_planetary_consumption days = 3650 } }
	}

	option = { name = xenomorph_op.56.a }
}

###############################################
# === xenomorph_lustful_void_compat_events.txt ===
###############################################
###############################################
# Xenomorph + Lustful Void Compatibility Events
#
# External-mod compatibility events for Lustful Void civic/trait logic.
###############################################

# Xenomorph + Lustful Void Compatibility Events
# Place in: events/xenomorph_lustful_void_compat_events.txt

namespace = xeno_lv_compat

# Run this from yearly_country_pulse/on_yearly_pulse.
# It handles the dynamic slave/no-slave and opposite-sex captive bonuses.
country_event = {
	id = xeno_lv_compat.10
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		OR = {
			has_valid_civic = civic_xenomorph_matriarchs_hunger
			has_valid_civic = civic_xenomorph_patriarchs_dominion
		}
	}

	immediate = {
		# Matriarchal Hunger: penalty if no slaves.
		if = {
			limit = {
				has_valid_civic = civic_xenomorph_matriarchs_hunger
				NOT = { xeno_has_any_slave_pop = yes }
			}
			add_modifier = { modifier = xeno_matriarchal_hunger_no_slaves_penalty days = 370 }
		}
		else_if = {
			limit = { has_modifier = xeno_matriarchal_hunger_no_slaves_penalty }
			remove_modifier = xeno_matriarchal_hunger_no_slaves_penalty
		}

		# Patriarchal Dominion: penalty if no slaves.
		if = {
			limit = {
				has_valid_civic = civic_xenomorph_patriarchs_dominion
				NOT = { xeno_has_any_slave_pop = yes }
			}
			add_modifier = { modifier = xeno_patriarchal_dominion_no_slaves_penalty days = 370 }
		}
		else_if = {
			limit = { has_modifier = xeno_patriarchal_dominion_no_slaves_penalty }
			remove_modifier = xeno_patriarchal_dominion_no_slaves_penalty
		}

		# Matriarchal Hunger: +25% pop growth if any enslaved all-male species exists.
		if = {
			limit = {
				has_valid_civic = civic_xenomorph_matriarchs_hunger
				xeno_has_enslaved_all_male_species = yes
			}
			add_modifier = { modifier = xeno_matriarchal_hunger_all_male_slave_bonus days = 370 }
		}
		else_if = {
			limit = { has_modifier = xeno_matriarchal_hunger_all_male_slave_bonus }
			remove_modifier = xeno_matriarchal_hunger_all_male_slave_bonus
		}

		# Patriarchal Dominion: +25% pop growth if any enslaved all-female species exists.
		if = {
			limit = {
				has_valid_civic = civic_xenomorph_patriarchs_dominion
				xeno_has_enslaved_all_female_species = yes
			}
			add_modifier = { modifier = xeno_patriarchal_dominion_all_female_slave_bonus days = 370 }
		}
		else_if = {
			limit = { has_modifier = xeno_patriarchal_dominion_all_female_slave_bonus }
			remove_modifier = xeno_patriarchal_dominion_all_female_slave_bonus
		}
	}
}

# Optional startup cleanup: makes the main Xenomorph species match the civic sex trait.
# This intentionally targets Xenomorph species only, not enslaved host species.
country_event = {
	id = xeno_lv_compat.20
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		OR = {
			has_valid_civic = civic_xenomorph_matriarchs_hunger
			has_valid_civic = civic_xenomorph_patriarchs_dominion
		}
	}

	immediate = {
		if = {
			limit = { has_valid_civic = civic_xenomorph_matriarchs_hunger }
			every_owned_species = {
				limit = { has_trait = trait_xenomorph }
				remove_trait = trait_lv_all_male
				add_trait = trait_lv_all_female
			}
		}
		if = {
			limit = { has_valid_civic = civic_xenomorph_patriarchs_dominion }
			every_owned_species = {
				limit = { has_trait = trait_xenomorph }
				remove_trait = trait_lv_all_female
				add_trait = trait_lv_all_male
			}
		}
	}
}


# Brood Queen Hive LV synergy.
# When LV is loaded AND a planet has Brood Queen Hive, apply the LV bonus modifier.
# Fires from on_yearly_pulse_country.
country_event = {
	id = xeno_lv_compat.30
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		has_global_flag = lustful_void_mod_loaded
		any_owned_planet = {
			has_building = building_xenomorph_brood_queen_hive
		}
	}

	immediate = {
		every_owned_planet = {
			if = {
				limit = {
					has_building = building_xenomorph_brood_queen_hive
					NOT = { has_modifier = xenomorph_brood_queen_hive_lv_bonus }
				}
				add_modifier = { modifier = xenomorph_brood_queen_hive_lv_bonus days = -1 }
			}
			if = {
				limit = {
					NOT = { has_building = building_xenomorph_brood_queen_hive }
					has_modifier = xenomorph_brood_queen_hive_lv_bonus
				}
				remove_modifier = xenomorph_brood_queen_hive_lv_bonus
			}
		}
	}
}


# Detect Lustful Void at game start by checking for known LV civics.
# Sets has_global_flag = lustful_void_mod_loaded for downstream events.
country_event = {
	id = xeno_lv_compat.1
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		if = {
			limit = {
				NOT = { has_global_flag = lustful_void_mod_loaded }
				OR = {
					has_civic = civic_lv_divine_coupling
					has_civic = civic_lv_sex_crazed_breeders
					has_civic = civic_lv_milk_ranchers
					has_civic = civic_lv_sex_slaves
					has_civic = civic_lv_pleasure_suits
					has_civic = civic_lv_sexculture
					has_civic = civic_lv_franchised_prostitution
					has_civic = civic_lv_sex_contractors
					has_civic = civic_lv_machine_nurture_protocols
					has_civic = civic_lv_gestalt_pod_bondage
				}
			}
			set_global_flag = lustful_void_mod_loaded
		}
	}
}
